import java.io.*;
import java.net.*;

public class MartiniPommitusServer{
  public static void main(String[] arg) throws Exception{
    ServerSocket ss=new ServerSocket(1500);
	Socket sc1=ss.accept();
    PrintWriter vorku1=new PrintWriter(sc1.getOutputStream(), true);
    BufferedReader br1=new BufferedReader(new InputStreamReader(sc1.getInputStream()));
	vorku1.println("Tere tulemast, oota paarilist, joonista paberile laevad!");
	Socket sc2=ss.accept();
    PrintWriter vorku2=new PrintWriter(sc2.getOutputStream(), true);
    BufferedReader br2=new BufferedReader(new InputStreamReader(sc2.getInputStream()));
	vorku2.println("Tere tulemast, joonista paberile laevad!");	
	vorku1.println("Paariline olemas, vajuta enter, kui laevad valmis. Oota vastase kinnitust");
	br1.readLine();
	vorku2.println("Paarilisel laevad valmis, kui sul ka, vajuta enter");
	br2.readLine();
	while(true){
	   vorku1.println("paku");
	   String rida=br1.readLine();
	   vorku2.println("pakuti "+rida+". Vasta 'pihtas' või paku ise");
	   rida=br2.readLine();
	   vorku1.println("pakuti "+rida);
	}
  }
}